#include "placementGerme.h"

PlacementGerme::PlacementGerme(const char* file)
{
	filename=file;
}

void PlacementGerme::division()
{
	srand(time(NULL));
	int a;
	cout<<"Choississez en combien divise l'image"<<endl;
	cin>>a;
	IplImage * image = cvLoadImage(filename);
	
	diviser(a,image);
	
	cvNamedWindow("test");
	cvShowImage("test", image);
	cvWaitKey(0);	
}

void PlacementGerme::setListeGerme(vector<Germe*> *l)
{
	listeGerme=l;
}

void PlacementGerme::diviser(double div,IplImage * image)
{
	double largeur = image->width/div;
	double longueur = image->height/div;
	
	for(double i=0;i<div;i++)
	{
		cvLine(image, cvPoint(largeur*i ,0), cvPoint(largeur*i, image->height), CV_RGB(255,0,0), 1);
		cvLine(image, cvPoint(0, longueur*i), cvPoint(image->width, longueur*i), CV_RGB(255,0,0), 1);
	}
	
	int tempLar,tempLong;
	for(int i=0;i<div;i++)
	{
		for(double a=0;a<div;a++)
		{
			
			tempLar = rand()%((int)largeur)+(largeur*a);
			tempLong= rand()%((int)longueur)+(longueur*i);
			
			Germe * temp = new Germe(tempLar,tempLong);
			listeGerme->push_back(temp);
			
			cvLine(image, cvPoint(tempLar,tempLong), cvPoint(tempLar,tempLong), CV_RGB(0,255,0), 3);
		}
	}
}